﻿@{
    ViewBag.Title = "DangAn";
    Layout = "~/Views/Shared/ShouYe.cshtml";
}

<script src="~/BootstrapSouce/js/jquery.min.js"></script>
<link href="~/BootstrapSouce/css/bootstrap.min.css" rel="stylesheet" />
<script src="~/BootstrapSouce/js/bootstrap.min.js"></script>
<h2>档案库</h2>
<a href="/XBK/DangAnAdd"><input id="Button1" type="button" value="添加档案" class="btn-success" /></a>

<table class="table table-bordered table-hover definewidth m10" id="tb">

    <tr>
        <td><input id="CheckboxAll" type="checkbox" /></td>
        <td>编号</td>
        <td>档案名称</td>
        <td>备注</td>
        <td>操作</td>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td><input id='Check[]' name='Check[]' type="checkbox" value="@item.DangAn_ID" /></td>
            <td>@item.DangAn_ID</td>
            <td>@item.DangAn_Name</td>
            <td>@item.DangAn_Beizhu</td>
            <td><a href="/XBK/XiangQin/@item.DangAn_ID">查看</a>|<a href="javascript:void(0);" onclick="DEL(@item.DangAn_ID)">删除</a></td>
        </tr>
    }
</table>
<input id="Button1" type="button" value="批量删除" onclick="DELETE()" />
<script>
    function DEL(ID)
    {
        if(confirm('真的要删除么?'))
        {
            $.ajax({
                type:"get",
                url:"/XBK/DangAnDEL/"+ID,
                success:function(obj)
                {

                    if (obj > 0) {
                        alert('删除成功');
                        location.href = '/XBK/DangAn';
                    }
                    else {
                        alert("删除失败");
                    }
                }
                })
        }
    }

    $("#CheckboxAll").bind('click', function () {
        $("input[name='Check[]']").prop("checked", this.checked);
    })
    function DELETE() {
      
            var cheks = $("input[name='Check[]']:checked");
            if (cheks.length == 0)
            {
                alert("未选中任何项");
            }
    
            var sid = "";
            for (var i = 0; i < cheks.length; i++) {
                sid += cheks[i].value + ','; }
                var id = sid.substr(0, sid.length - 1)
              
                if (confirm("确定要删除选中项？"))
                {
                    $.ajax({
                        type: "get",
                        url: "/XBK/DangAnDEL/" + id,
                        success: function (obj) {

                            if (obj > 0) {
                                alert('删除成功');
                                location.href = '/XBK/DangAn';
                            }
                            else {
                                alert("删除失败");
                            }
                        }
                    })
                }
           
        
    }
</script>
